#ifndef M_CONFIG_H
#define M_CONFIG_H

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <limits.h>

struct addr {
	//char ip[20];
	struct in_addr ip;
	unsigned short port;
};

struct http_attr {
	char *attr_name;
	char *attr_value;
};

struct http_request {
	char method[10];
	char http_ver[5];
	int attr_num;
	struct http_attr *attr;
};

typedef struct {
	int url_server_num;
	struct addr *url_server;
	int page_server_num;
	struct addr *page_server;
	struct addr manage;
	int threads_num;
	int per_thread_conn;
	int per_thread_uris;
	int per_site_conn;
	struct http_request req_header;
/*
 * 向线程发送命令的字段
 * 2表示退出命令
 * */
	int cmd;	
	char regular[1024];
	char file_temp[PATH_MAX];
	/*
	 * 已加载该配置的线程数
	 * */
	//int load_thread;
	/*
	 * 初始化配置时的时间值
	 * */
	time_t init_time;
}CONF;

#define CONF_QUIT 2

extern CONF conf;
int init(const char *conf_file);
void destroy_conf(CONF *conf);
void conf_cpy(CONF *dst, CONF *src);

#define DEFAULT_THREADS_NUM 10
#define DEFAULT_PER_THREAD_CONN 100
#define DEFAULT_PER_THREAD_URLS 50
#define DEFAULT_PER_SITE_CONN 20
#define DEFAULT_METHOD "GET"
#define DEFAULT_HTTP_VER "1.1"

#endif
